import { formatDate } from '@src/assets/js/tool'
import { CaseSchema } from '@src/components/schema/caseSchema'
import { Space, Divider } from 'antd'
import { ColumnsType } from 'antd/es/table'
import Serieno from '@src/pages/admin/components/serieno'
import { Dispatch } from 'redux'
import { addWindow } from '@src/redux/actions/tab'

export function getColumn (dispatch: Dispatch): ColumnsType<CaseSchema> {
  const columns: ColumnsType<CaseSchema> = [
    {
      title: '序号',
      dataIndex: 'orderno',
      key: 'orderno',
      width: 75
    },
    {
      title: '案号',
      dataIndex: 'caseno_desc',
      key: 'caseno_desc',
      width: 140,
      render: (v: string, l: CaseSchema) => {
        return (
          <span>
            <span>{v}</span>
            <Serieno data={l} />
          </span>
        )
      }
    },
    {
      title: '申请人',
      dataIndex: 'applicant_name',
      key: 'applicant_name',
      width: 140
    },
    {
      title: '被申请人',
      dataIndex: 'respondent_name',
      key: 'respondent_name',
      width: 140
    },
    {
      title: '受理秘书',
      dataIndex: 'accepter',
      key: 'accepter',
      width: 90
    },
    {
      title: '办案秘书',
      dataIndex: 'processer',
      key: 'processer',
      width: 90
    },
    {
      title: '仲裁程序',
      dataIndex: 'procedure',
      key: 'procedure',
      width: 90
    },
    {
      title: '立案时间',
      dataIndex: 'docket_datetime',
      key: 'docket_datetime',
      width: 95,
      render: (v: number) => {
        if (typeof v === 'number') {
          return formatDate(v, 'YY.MM.DD')
        }
      }
    },
    {
      title: '归档时间',
      dataIndex: 'file_datetime',
      key: 'file_datetime',
      width: 95,
      render: (v: number) => {
        if (typeof v === 'number') {
          return formatDate(v, 'YY.MM.DD')
        }
      }
    },
    {
      title: '结案类型',
      dataIndex: 'closure_type',
      key: 'closure_type',
      width: 95
    },
    {
      title: '组庭时间',
      dataIndex: 'assign_datetime',
      key: 'assign_datetime',
      width: 95,
      render: (v: number) => {
        if (typeof v === 'number') {
          return formatDate(v, 'YY.MM.DD')
        }
      }
    },
    {
      title: '操作',
      dataIndex: 'id',
      key: 'id',
      width: 135,
      render: (v: string, l: CaseSchema) => {
        return (
          <Space split={<Divider type="vertical" />}>
            <a onClick={() => {
              dispatch(addWindow({ id: `case-input-${l.id}`, title: `${l.caseno_desc}`, componentName: 'CaseInputDetail', forceRefresh: false, meta: { id: l.id } }))
            }}>编辑</a>
          </Space>
        )
      }
    }
  ]
  return columns
}
